package com.javakc.platform.modules.circle.info.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javakc.platform.components.validation.group.Insert;
import com.javakc.platform.components.validation.group.Update;
import com.javakc.platform.modules.circle.info.entity.CircleInfo;
import com.javakc.platform.modules.circle.info.service.CircleInfoService;
import com.javakc.platform.modules.system.logger.component.annotation.LoggerOperation;
import com.javakc.platform.modules.system.logger.component.enumerate.LoggerEnumerate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * 圈子信息 接口
 */

@Api(tags = "[圈子信息接口]")
@RestController
@RequestMapping("circle/info")
public class CircleInfoController {

//    注入逻辑层实现类
    @Autowired
    private CircleInfoService circleInfoService;

    @PostMapping
    @ApiOperation(value = "新增圈子信息", consumes = "application/json",produces = "application/json")//对于操作接口进行描述
//    添加方法    consumes 参数形式格式    produces 服务器返回响应格式
//    (consumes = "application/json",produces = "application/json")
@ApiImplicitParams({
        @ApiImplicitParam(name="title",value = "圈子标题",required = true,dataTypeClass = String.class),
        @ApiImplicitParam(name="remarks",value = "圈子介绍",dataTypeClass = String.class),
        @ApiImplicitParam(name="circleTypeId",value = "圈子类型外键",required = true,dataTypeClass = String.class)
})
//           Insert.class分到添加组

//    AOP添加日志
    @LoggerOperation(module = "圈子信息",message = "新增圈子",type = LoggerEnumerate.INSERT)//
//   方法调用之前验证有没有该权限
    @PreAuthorize("hasAuthority('circle:info:save')")
    public void  save(@RequestBody @Validated({Insert.class})  CircleInfo entity){
        circleInfoService.save(entity);
    }

//    修改方法
    @PutMapping
    @ApiOperation(value = "编辑圈子信息", consumes = "application/json",produces = "application/json")//对于操作接口进行描述
//    添加方法    consumes 参数形式格式    produces 服务器返回响应格式
//    (consumes = "application/json",produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "圈子主键",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name="title",value = "圈子标题",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name="remarks",value = "圈子介绍",dataTypeClass = String.class),
            @ApiImplicitParam(name="circleTypeId",value = "圈子类型外键",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name="revision",value = "乐观锁",required = true,dataTypeClass = Integer.class)
    })

//    为修改方法添加AOP修改日志
    @LoggerOperation(module = "圈子信息",message = "新增圈子",type = LoggerEnumerate.UPDATE)//
    @PreAuthorize("hasAuthority('circle:info:update')")
    public void  update(@RequestBody @Validated({Update.class}) CircleInfo entity){
        circleInfoService.updateById(entity);
    }
//    单个删除 通过id查找单个删除
    @DeleteMapping("{id}")
    @ApiOperation(value = "删除圈子信息")//对于操作接口进行描述
    @ApiImplicitParam(name="id",value = "圈子主键",required = true,dataTypeClass = Integer.class)
    @LoggerOperation(module = "圈子信息",message = "单删圈子",type = LoggerEnumerate.DELETE)//
    @PreAuthorize("hasAuthority('circle:info:delete')")
    public void delete(@PathVariable int id){
        circleInfoService.removeById(id);
    }


//   批量删除
    @DeleteMapping
    @ApiOperation(value = "批量删除圈子信息")//对于操作接口进行描述
    @ApiImplicitParam(name="array",value = "圈子主键数组",required = true,dataTypeClass = List.class)
    @LoggerOperation(module = "圈子信息",message = "批删圈子",type = LoggerEnumerate.DELETE)//
    @PreAuthorize("hasAuthority('circle:info:batch')")
    public void delete(@RequestBody Collection<Integer> list){

        circleInfoService.removeBatchByIds(list);

    }

//    单条查询
    @GetMapping("{id}")
    @ApiOperation(value = "主键查询圈子信息")//对于操作接口进行描述
    @ApiImplicitParam(name="id",value = "圈子主键",required = true,dataTypeClass = Integer.class)
    @LoggerOperation(module = "圈子信息",message = "单查圈子")//
    @PreAuthorize("hasAuthority('circle:info:load')")
    public CircleInfo load(@PathVariable int id){

        return circleInfoService.getById(id);
    }
//    按条件分页查询  pageNo 查询第几页  pageSize 每页查询几条
    @PostMapping("page") //get请求 json不能带复杂类型
    @ApiOperation(value = "分页条件查询圈子信息")//对于操作接口进行描述
//    添加方法    consumes 参数形式格式    produces 服务器返回响应格式
//    (consumes = "application/json",produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name="title",value = "圈子标题",dataTypeClass = String.class),
            @ApiImplicitParam(name="pageNo",value = "起始页码",dataTypeClass = Integer.class),
            @ApiImplicitParam(name="pageSize",value = "每页条数",dataTypeClass = Integer.class),

    })
    @LoggerOperation(module = "圈子信息",message = "分页条件查询圈子")//
    @PreAuthorize("hasAuthority('circle:info:page')")
    public Page<CircleInfo> page(@RequestBody CircleInfo entity){
        return circleInfoService.page(entity);
    }
}
